    var game;
    var cursor=0;
    var mvs;
    var canvas;
    var context;
    
    function cat(func) {
      try {
        func();
      } catch (ex) {
        alert(ex);
      }
    }
    
    function next() { 
      cat(function() {
        if (cursor > mvs.length) {
		return;
	}            
        game.onemove(canvas, mvs[cursor++].san);
        context.save();
      });
    }

    function prev() {
      cat(function() {
        if (cursor == 0) {
		return;
	}            
        cursor--;
        context.restore();
      });
    }

    function init(json) {
      try {
	canvas = document.getElementById("board");
        context = canvas.getContext("2d");    
  	mvs = json
      	game = Chessboard.newGame();
        game.setFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR");
        game.draw("board");
      } catch (ex) {
        alert(ex);
      }
    }
